/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package docview;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;

/**
 *
 * @author Admin
 */
public class CutAction extends Action
{
    private int colS = -1;
    private int colE = -1;
    private int rowS = -1;
    private int rowE = -1;
    public void actionPerformed(ActionEvent e)
    {
        int[]rows = table.getSelectedRows();
        int[]cols = table.getSelectedColumns();
        if (rows.length == 0 && cols.length == 0) return;
        StringBuffer sbf = new StringBuffer();
        if (rows.length > 0 && cols.length > 0 )
        {
            rowS = rows[0];
            colS = cols[0];
            rowE = rows[rows.length-1];
            colE = cols[cols.length-1];
        }
        for (int i = rowS; i <= rowE; i++)
        {
             for (int j = colS; j <= colE; j++)
             {
                 //if (j+1==colE)
                   // sbf.append(table.getValueAt(i, j));
                 //else
                     sbf.append(table.getValueAt(i, j)+"\t");
             }
             sbf.append("\n");
        }
        StringSelection stsel = new StringSelection(sbf.toString());
        Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
        system.setContents(stsel, stsel);
        table.setTextToSubtable(rowS, colS, rowE, colE, "");
    }
}
